<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../resources/common.js"></script>
<script src="../resources/picker-common.js"></script>
<script src="../calendar-picker/resources/calendar-picker-common.js"></script>
</head>
<body>
<input type="week" id="week-0" value="2019-W07">
<input type="week" id="week-1" value="2019-W07">
<script>

promise_test(() => {
  let weekElement = document.getElementById('week-0');
  return openPickerWithPromise(weekElement)
  .then(() => {
    // Make the picker dismiss synchronously so we don't need to insert
    // an artificial delay in the test
    internals.pagePopupWindow.CalendarPicker.commitDelayMs = 0;

    clickMonthPopupButton();
    eventSender.keyDown('ArrowRight');
    eventSender.keyDown('ArrowDown');
    eventSender.keyDown('Enter');
    assert_equals(weekElement.value, "2019-W28", "Month chooser button should have changed month");

    eventSender.keyDown('Enter');
    assert_equals(internals.pagePopupWindow, null, "Enter key should have dismissed popup.");
  });
}, "Week picker: Month chooser should allow user to chooser month");

promise_test(() => {
  let weekElement = document.getElementById('week-1');
  return openPickerWithPromise(weekElement)
  .then(() => {
    // Make the picker dismiss synchronously so we don't need to insert
    // an artificial delay in the test
    internals.pagePopupWindow.CalendarPicker.commitDelayMs = 0;

    clickMonthPopupButton();
    eventSender.keyDown('ArrowRight');
    eventSender.keyDown('ArrowDown');
    eventSender.keyDown('Escape');
    clickDayCellAt(2, 2);

    assert_equals(weekElement.value, "2019-W07", "Escape key should have dismissed month chooser without changing month ");
  });
}, "Week picker: Month chooser should dismiss on Escape key");

</script>
</body>
</html>
